<template>
  <div>
    <el-upload
      :action="postUrl"
      :headers="headers"
      list-type="picture-card"
      :file-list="fileList"
      :on-preview="onPreview"
      :on-remove="onRemove"
      :on-success="onSuccess"
    >
      <i slot="default" class="el-icon-plus" />
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="imgUrl" alt="">
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'ShopImage',
  data() {
    return {
      imgUrl: '',
      dialogVisible: false,
      fileList: [],
      postUrl: 'https://www.liulongbin.top:8888/api/private/v1/upload',
      headers: {
        Authorization: this.$store.state.user.token
      },
      pics: []// 图片临时路径
    }
  },

  created() {

  },
  methods: {
    // 预览图片
    onPreview(file) {
      this.imgUrl = file.url
      this.dialogVisible = true
    },
    // 删除图片
    onRemove(file, fileList) {
      this.fileList = fileList
    },
    // 上传图片成功
    onSuccess(response) {
      console.log(response)
      this.pics.push({ pic: response.data.tmp_path })
      this.$emit('addImage', this.pics)
    }
  }
}
</script>

<style scoped lang='less'>

</style>
